import request from '@/utils/request'
import { ResMenuByRole, QueryMenuByRole, SetMenuReq } from '@/model/system/UpdateRoleMenu'
import { ResMenuTree, MenuQuery,SaveMenu } from '@/model/system/MenuTree'

/**
 * 根据角色id获取所有菜单
 * @param data
 * @returns
 */
export function listByRole(data: QueryMenuByRole): Promise<Array<ResMenuByRole>> {
  return request.get<Array<ResMenuByRole>>('/api/auth/module/listByRole', data)
}

/**
 * 根据角色id设置菜单
 * @param data
 * @returns
 */
export function saveSetMenu(data: SetMenuReq): Promise<null> {
  return request.post<null>('/api/auth/module/updateModuleByRole', data)
}
/**
 * 获取所有菜单
 * @param data
 * @returns
 */
export function getTreeMenu(data: MenuQuery): Promise<Array<ResMenuTree>> {
  return request.get<Array<ResMenuTree>>('/api/auth/module/list', data)
}
/**
 * 新增菜单
 * @param data
 * @returns
 */
export function addMenu(data: SaveMenu): Promise<null> {
  if (data.parentId == null) data.parentId = 0
  return request.post('/api/auth/module', data)
}
/**
 * 修改菜单
 * @param data
 * @returns
 */
export function updateMenu(data: SaveMenu): Promise<null> {
  if (data.parentId == null) data.parentId = 0
  return request.put('/api/auth/module/' + data.id, data)
}
/**
 * 删除菜单
 * @param id
 */
export function removeMenu(id: number): Promise<null> {
  return request.delete('/api/auth/module/' + id)
}
